package com.yuncheng.spcyApi.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import javax.annotation.Resource;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.entity.SpcyRsDwk;
import com.yuncheng.spcyApi.service.ISpcyRsDwkService;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * @Description: 审评查验-单位库管理
 * @Author: yuncheng
 * @Date: 2024-01-05
 * @Version: V1.0
 */
@Api(tags = "审评查验-单位库管理接口")
@RestController
@RequestMapping("/api/spzx-spcy/dwk")
public class SpcyRsDwkController  {

    @Resource
    private ISpcyRsDwkService spcyRsDwkService;


    @Log(title = "单位库-分页列表查询")
    @ApiOperation(value = "单位库-分页列表查询")
    @GetMapping(value = "/pageList")
    public HttpResult<?> queryPageList(SpcyRsDwk query, String gjz, PageVo pageVo, OrderItemVo orderItemVo) {

        return HttpResult.ok(spcyRsDwkService.selectPageList(query, gjz, pageVo, orderItemVo));
    }

    @ApiOperation(value = "单位库列表")
    @GetMapping(value = "/dwList")
    public HttpResult<?> dwList(SpcyRsDwk query, String gjz, OrderItemVo orderItemVo) {

        return HttpResultVo.HttpResultList(spcyRsDwkService.selectList(query, gjz, orderItemVo));
    }

    @Log(title = "单位库-添加")
    @ApiOperation(value = "单位库-添加")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody SpcyRsDwk bean) {

        return HttpResultVo.HttpResultSave(spcyRsDwkService.addDw(bean), "添加成功");
    }

    @Log(title = "单位库-编辑")
    @ApiOperation(value = "单位库-编辑")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {

        spcyRsDwkService.updatwDw(buffer);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "单位库-删除")
    @ApiOperation(value = "单位库-删除")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam(value = "id",defaultValue = "") String id) {

        spcyRsDwkService.deleteDw(id);
        return HttpResult.ok("删除成功");
    }

}
